<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #first {
            width: 300px;
            height: 500px;
            border: 1px solid red;
            margin: 0 auto;
        }

        #first img {
            width: 240px;
            height: 300px;
            margin: 30px;
        }

        #first span {
            text-align: center;
            font-size: 12px;
            display: block;

        }

        #first .three {
            text-align: center;
            
        }

        #first>p {
            text-align: center;
            /* overflow: hidden; */
            margin: 20px 100px;
        }

        .one {
            margin: 25px 80px;
            overflow: hidden;
        }

        .one #num {
            width: 50px;
            height: 19px;
            /* display: inline-block; */
            background: white;
            border: 1px solid black;
            text-align: center;
            float: left;
            border-left: 0;
            border-right: 0;
        }

        .one #btn1 {
            width: 22px;
            height: 22px;
            background: white;
            border: 1px solid black;
            /* vertical-align: middle; */
            text-align: center;
            float: left;
        }

        .one #btn2 {
            width: 22px;
            height: 22px;
            background: white;
            border: 1px solid black;
            /* vertical-align: middle; */
            text-align: center;
            float: left;
        }

        .one b {
            /* display: inline-block; */
            float: left;
        }

        .two {
            text-align: center;
            /* overflow: hidden; */

        }
    </style>
</head>

<body>
    <div id="first">
        <img src="../练习/2.jpg" alt="">
        <span>纪梵希&nbsp;小羊皮口红304</span>
        <div class="three">￥<b id="price">340</b></div>
        <div class="one">
            <b>数量</b>
            <input type="button" value="-" id="btn1">
            <input type="text" value="0" id="num">
            <input type="button" value="+" id="btn2">
        </div>
        <div class="two">总价￥：<strong id="total"></strong> </div>

    </div>
    <script>
        var hhp_btn1 = document.getElementById("btn1")
        var hhp_btn2 = document.getElementById("btn2")
        hhp_btn1.onclick = function () {
            num.value=parseInt(num.value)-1;
            if(num.value<=0){
                num.value=0;
            }
            total.innerHTML=num.value*price.innerHTML;
            
        }
        hhp_btn2.onclick = function () {
            num.value=parseInt(num.value)+1;
            total.innerHTML=num.value*price.innerHTML;
        }

    </script>
</body>

</html>